package crm.view.Employee;

import crm.Utils.RoundBorder;
import crm.dao.impl.EmployeeSqlSeverImpl;
import crm.entity.Customer;
import crm.entity.Employee;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

/**
 * 查看职员基本信息
 */
public class EmployeeBasicInfo implements ActionListener {
    JFrame frame = null;
    JLabel id = null;
    JLabel name = null;
    JLabel pwd = null;
    JLabel part = null;
    JLabel productsId = null;
    JLabel planId = null;
    JLabel salary = null;
    JLabel type = null;

    JTextField IdField = null;
    JTextField NameField = null;
    JTextField PwdField = null;
    JTextField partField = null;
    JTextField productsIdField = null;
    JTextField planIdFiled = null;
    JTextField salaryField = null;
    JTextField typeField = null;

    JButton btn1 = null;
    JButton btn2 = null;


    public static void main(String[] args) {
        new EmployeeBasicInfo();
    }

    public EmployeeBasicInfo() {
        init();
        frame.setBounds(680, 200, 600, 700);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setLayout(null);
        frame.setVisible(true);
    }

    public void init() {
        frame = new JFrame("客户基本信息");
        id = new JLabel("员工编号:");
        name = new JLabel("输入姓名:");
        pwd = new JLabel("员工密码:");
        part = new JLabel("所属部门:");
        planId = new JLabel("计划编号:");
        productsId = new JLabel("产品编号:");
        salary = new JLabel("员工薪水:");
        type = new JLabel("员工类型:");
        IdField = new JTextField();
        NameField = new JTextField();
        PwdField = new JTextField();
        partField = new JTextField();
        planIdFiled = new JTextField();
        productsIdField = new JTextField();
        salaryField = new JTextField();
        typeField = new JTextField();
        btn1 = new JButton("查询");
        btn2 = new JButton("清空");
        ImageIcon icon1 = new ImageIcon("src/img/查询2.png");
        btn1.setIcon(icon1);
        btn1.setOpaque(false);// 设置原来按钮背景透明
        btn1.setBorder(new RoundBorder());
        btn1.setBorder(new RoundBorder(Color.PINK));
        ImageIcon icon2 = new ImageIcon("src/img/清空.png");
        btn2.setIcon(icon2);
        btn2.setOpaque(false);
        btn2.setBorder(new RoundBorder());
        btn2.setBorder(new RoundBorder(Color.PINK));
        Font font = new Font("宋体", 2, 20);
        btn1.setFont(font);
        btn2.setFont(font);
        id.setFont(font);
        IdField.setFont(font);
        name.setFont(font);
        NameField.setFont(font);
        pwd.setFont(font);
        PwdField.setFont(font);
        part.setFont(font);
        partField.setFont(font);
        planId.setFont(font);
        planIdFiled.setFont(font);
        productsId.setFont(font);
        productsIdField.setFont(font);
        salary.setFont(font);
        salaryField.setFont(font);
        type.setFont(font);
        typeField.setFont(font);


        frame.add(btn1);
        frame.add(btn2);

        frame.add(id);
        frame.add(IdField);
        frame.add(name);
        frame.add(NameField);
        frame.add(pwd);
        frame.add(PwdField);
        frame.add(part);
        frame.add(partField);
        frame.add(planId);
        frame.add(planIdFiled);
        frame.add(productsId);
        frame.add(productsIdField);
        frame.add(salary);
        frame.add(salaryField);
        frame.add(type);
        frame.add(typeField);


        name.setBounds(40, 40, 100, 60);
        NameField.setBounds(150, 50, 300, 40);

        btn1.setBounds(170, 100, 110, 40);
        btn2.setBounds(330, 100, 110, 40);

        id.setBounds(40, 140, 100, 60);
        IdField.setBounds(150, 150, 300, 40);
        IdField.setEditable(false);

        pwd.setBounds(40, 190, 100, 60);
        PwdField.setBounds(150, 200, 300, 40);
        PwdField.setEditable(false);

        part.setBounds(40, 240, 100, 60);
        partField.setBounds(150, 250, 300, 40);
        partField.setEditable(false);

        planId.setBounds(40, 290, 100, 60);
        planIdFiled.setBounds(150, 300, 300, 40);
        planIdFiled.setEditable(false);

        productsId.setBounds(40, 340, 100, 60);
        productsIdField.setBounds(150, 350, 300, 40);
        productsIdField.setEditable(false);


        salary.setBounds(40, 390, 100, 60);
        salaryField.setBounds(150, 400, 300, 40);
        salaryField.setEditable(false);

        type.setBounds(40, 440, 100, 60);
        typeField.setBounds(150, 450, 300, 40);
        typeField.setEditable(false);

        btn1.addActionListener(this);
        btn2.addActionListener(this);
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        Employee employee = new Employee();
        EmployeeSqlSeverImpl dao = new EmployeeSqlSeverImpl();
        if ("查询".equals(e.getActionCommand())) {
            if ("".equals(NameField.getText())) {
                JOptionPane.showMessageDialog(null, "请输入你的姓名进行查询！");
            } else {
                String name = NameField.getText();
                List<Employee> getname = dao.getByName(name);
                for (Employee employee1 : getname) {
                    IdField.setText(String.valueOf(employee1.getEmployee_id()));
                    PwdField.setText(String.valueOf(employee1.getEmployee_pwd()));
                    NameField.setText(String.valueOf(employee1.getEmployee_name()));
                    partField.setText(String.valueOf(employee1.getEmployee_part()));
                    salaryField.setText(String.valueOf(employee1.getEmployee_salary()));
                    planIdFiled.setText(String.valueOf(employee1.getPlan_id()));
                    productsIdField.setText(String.valueOf(employee1.getProducts_id()));
                    typeField.setText(String.valueOf(employee1.getEmployee_type()));

                }

            }
        } else if ("清空".equals(e.getActionCommand())) {
            NameField.setText("");
            IdField.setText("");
            partField.setText("");
            PwdField.setText("");
            productsIdField.setText("");
            planIdFiled.setText("");
            salaryField.setText("");
            typeField.setText("");


        }


    }
}
